package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.ShareExplosion;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌列表适配器
 */
public class ShareExplosionItemGridViewAdapter extends BaseAdapter{

	private Context context;
	private LayoutInflater inflater;
	private List<ShareExplosion.DataBean.ListBean> serviceareaList;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	private boolean isChenck=false;
	private ArrayList<String> ar=new ArrayList<String>();
	public ShareExplosionItemGridViewAdapter(Context context, List<ShareExplosion.DataBean.ListBean> serviceareaList){
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.serviceareaList=serviceareaList;
	}
	@Override
	public int getCount() {
		return serviceareaList == null ? 0 : serviceareaList.size();
	}

	@Override
	public Object getItem(int position) {
		return serviceareaList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public List<ShareExplosion.DataBean.ListBean> getServiceareaList() {
		return serviceareaList;
	}

	public void setServiceareaList(List<ShareExplosion.DataBean.ListBean> serviceareaList) {
		this.serviceareaList = serviceareaList;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.share_explosion_item_gridview_adapter, null);
			holder = new ViewHolder();
			holder.iv_share_explosion_imageshop= (ImageView) convertView.findViewById(R.id.iv_share_explosion_imageshop);
			holder.tv_share_explosion_name= (TextView) convertView.findViewById(R.id.tv_share_explosion_name);
			holder.tv_share_explosion_price= (TextView) convertView.findViewById(R.id.tv_share_explosion_price);
			holder.tv_share_explosion_ds_price= (TextView) convertView.findViewById(R.id.tv_share_explosion_ds_price);
			holder.tv_share_explosion_red_juan= (TextView) convertView.findViewById(R.id.tv_share_explosion_red_juan);
			holder.tv_share_explosion_Have_snapped_up= (TextView) convertView.findViewById(R.id.tv_share_explosion_Have_snapped_up);
			holder.tv_share_explosion_xiaoshu_price= (TextView) convertView.findViewById(R.id.tv_share_explosion_xiaoshu_price);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		final ShareExplosion.DataBean.ListBean bean=serviceareaList.get(position);
		Log.e("数据","Gridviewbean=========="+bean.getMainImageUrl());
		uploadimageview(holder.iv_share_explosion_imageshop,bean.getMainImageUrl(),null,context);
		holder.tv_share_explosion_name.setText("\t\t\t\t"+bean.getGoodsName());
		holder.tv_share_explosion_price.setText("¥"+bean.getPrice());
		try {
			String  price= String.valueOf(bean.getConPrice());
			String a=price.substring(0, price.indexOf("."));
			String b=price.substring(price.indexOf("."));
			holder.tv_share_explosion_ds_price.setText(a);
			holder.tv_share_explosion_xiaoshu_price.setText(b);
		}catch (Exception e){
			e.getMessage();
		}
		holder.tv_share_explosion_red_juan.setText(bean.getCouponMoney()+"元券");
		holder.tv_share_explosion_Have_snapped_up.setText("已抢"+bean.getTotalSales()+"件");
		return convertView;
	}
	
	
	
	class ViewHolder {
		
		private ImageView iv_share_explosion_imageshop;
		private TextView tv_share_explosion_name;
		private TextView tv_share_explosion_price;
		private TextView tv_share_explosion_ds_price;
		private TextView tv_share_explosion_red_juan;
		private TextView tv_share_explosion_Have_snapped_up;
		private TextView tv_share_explosion_xiaoshu_price;
	}

	public static void uploadimageview(final ImageView views, String url, String bili, Context c) {
		DisplayImageOptions HXOptions = new DisplayImageOptions.Builder()
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		ImageLoader.getInstance().displayImage(url, views, HXOptions);
	}
}
